window.onload = function() {
    var mySwiper = new Swiper(".swiper-container", {
        loop: true, // 循环模式选项

        // 如果需要分页器
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        autoplay: {
            delay: 2500, //事件间隔
            stopOnLastSlide: false, //
            disableOnInteraction: false,
            pauseOnMouseEnter: true, //输入移入 停止
        },
    });

}
location.search;
console.log(location.search);
let str = location.search.slice(1);
console.log(str);
let arr = str.split("&");
console.log(arr);
let pid = null;
arr.forEach((v) => {
    v; //id=2323
    let tempArr = v.split("=");
    if (tempArr[0] == "id") {
        pid = tempArr[1];
    }
});
console.log(pid);
let detailAPI = "http://jx.xuzhixiang.top/ap/api/detail.php";
let params = {
    id: pid
};
axios.get(detailAPI, {
    params
}).then((res) => {
    console.log(res.data);
    let pObj = res.data.data;
    console.log(pObj);
    document.querySelector(".pimg").src = pObj.pimg;
    document.querySelector(".pname").innerHTML = pObj.pname;
    document.querySelector(".pdesc").innerHTML = pObj.pdesc;
    document.querySelector(".pprice").innerHTML = '￥' + pObj.pprice;
});

// 加入购物车 事件
async function addCart() {
    let addCartAPI = "http://jx.xuzhixiang.top/ap/api/add-product.php";
    let uid = localStorage.getItem("id");
    pid; //
    let pnum = document.querySelector(".pnum").value;
    let params = {
        uid,
        pid,
        pnum
    };
    console.log(params);
    let {
        data
    } = await axios.get(addCartAPI, {
        params
    });
    console.log(data);
}
// 点击我的购物车
function myCartClick(btn) {
    console.log("aaa");
    console.log(btn);
    let uid = localStorage.getItem("id");
    if (uid) {} else {
        alert("请求登录");
        window.event.preventDefault();
    }
}
window.onload = function() {

    //index 用户展示
    if (localStorage.getItem('username')) {
        let yhm = document.querySelector('.wrapper-right-sp');
        console.log(yhm);
        yhm.innerHTML = "您好," + localStorage.getItem("username") + '<a href = "login.html" id = "exit" >退出</a>';
    }

    let exit = document.querySelector('#exit');
    exit.addEventListener('click', function() {
        localStorage.removeItem('username');
        setTimeout(() => {
            location.href = "login.html";
        }, 1000);
    })
}